package com.example.demo.business.controller.v1;

import com.example.demo.base.util.CommonUtil;
import com.example.demo.base.util.JsonUtil;
import com.example.demo.business.bean.base.ProxyRebase;
import com.example.demo.business.bean.entity.HConfig;
import com.example.demo.business.bean.vo.Banner1Vo;
import com.example.demo.business.bean.vo.BannerVo;
import com.example.demo.business.bean.vo.SplashVo;
import com.example.demo.business.bean.vo.VersionVo;
import com.example.demo.business.dao.HCategoryDao;
import com.example.demo.business.dao.HConfigDao;
import com.example.demo.business.dao.HUserDao;
import com.example.demo.business.service.AdService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

@RestController
@RequestMapping("/v1/index")
public class IndexController {

    @Autowired
    private AdService adService;


    @Autowired
    private HConfigDao hConfigDao;
    //获取闪屏广告和公告
    @GetMapping("/ad/splash")
    public Object getSplashAd(String token){
        return new SplashVo(adService.getSplashAppMent(),adService.getSplashAd());
    }

    //获取轮播图和公告
    @GetMapping("/ad/banner")
    public Object getIndexAd(String token){
        return new BannerVo(adService.getBanners(),adService.getBannerAppMent());
    }

    //获取轮播图和公告
    @GetMapping("/ad/special")
    public Object getSpecialAd(String token){
        return new Banner1Vo(adService.getSpecialAd(),adService.getSpecialAppMent());
    }

    //获取App版本更新信息
    @GetMapping("/version")
    public Object getVersion(String channel){
        return new VersionVo(1,"http://www.baidu.com");
    }

    @GetMapping("/ppp")
    public Object setAll(){
        HConfig hConfig1 = hConfigDao.findByKeyName("proxyRebate");
        String value = hConfig1.getKeyValue();
        String[] srt = JsonUtil.getObjByJsonString(value,String[].class);
        HConfig hConfig2 = hConfigDao.findByKeyName("proxyRatio");
        return "";
    }

    //广告点击临时增加次数
    @GetMapping("/ad/touch")
    public Object adTouch(String token){
        adService.addViewNum(token);
        return "";
    }
}
